/*
 * Alarm.h
 *
 *  Created on: 16.09.2011
 *      Author: windows97
 */

#ifndef ALARM_H_
#define ALARM_H_

#define ALARM_NONE_U8 ((uint8_t)(255U))
#define ALARM_LIGHTMODE_MULTIPLIER_U8 ((uint8_t)(15U)) /*minutes*/
#define ALARM_SLEEP_OFF_U8 ((uint8_t) (0U))
#define ALARM_CNT_U8  ((uint8_t)(5U))

typedef struct _T_Alarm {
  T_Time    Time_t;
  int16_t   Time2Al_s16;
  uint16_t  SoundMode_t   :3;
  uint16_t  LightMode_t   :6;
  uint16_t  Days_t; /* Days - Bitfield starting with Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, NextDay  - see @T_Day for details */
  uint16_t  Sleep_t       :4; /* SleepTime in Minutes */
  uint16_t  State_t       :3; /* 0 -> Disabled, 1 -> Enabled, 2 -> Active */
} T_Alarm;

typedef enum _T_Day
{
  Alarm_NoDay     = 0,
  Alarm_Mon       = 1,
  Alarm_Tue       = 2,
  Alarm_Wed       = 4,
  Alarm_Thu       = 8,
  Alarm_Fri       = 16,
  Alarm_Weekdays  = 31,
  Alarm_Sat       = 32,
  Alarm_Sun       = 64,
  Alarm_Weekend   = 96,
  Alarm_Once      = 128
} T_Day;

typedef enum _T_AlarmSound
{
  Alarm_SoundOff,
  Alarm_Beep,
  Alarm_Sound1,
  Alarm_Sound2
}T_AlarmSound;

#define Alarm_LightOff 0

typedef enum _T_AlarmState
{
  Alarm_Disabled,
  Alarm_Enabled,
  Alarm_PreActive,
  Alarm_Active,
  Alarm_Deactive,
  Alarm_Sleep,
  Alarm_StateUndefined
}T_AlarmState;

void AlaInit( void );
void AlaCyclic( void );
void AlaDeactivateAlarm( void );
uint8_t AlaGetNextAlarm( T_TimeDate* iTimeDate );
uint8_t AlaIsAnyAlarmEnabled( void );
int16_t AlaGetTime2NextAlarm( T_TimeDate* lTimeDate_t );
uint8_t AlaGetTimeOfNextAlarm( T_Time* lAlarmTime_t );
uint8_t AlaSetAlarm( T_Alarm* iAlarmData_t, uint8_t iAlarmIndex_u8 );
uint8_t AlaGetState( void );

#endif /* ALARM_H_ */
